package com.xs.designpattern;

import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 炼金术士商店
 * @author xs
 */
@Slf4j
public class AlchemistShop {
    /**
     * 顶层存放的药水
     */
    private final List<Potion> topShelf;
    /**
     * 底层存放的药水
     */
    private final List<Potion> bottomShelf;

    /**
     * 构造函数创建药品，重复药水类型归于一类.
     */
    public AlchemistShop() {
        PotionFactory factory = new PotionFactory();
        topShelf =
            Arrays.asList(factory.createPotion(PotionType.INVISIBILITY), factory.createPotion(PotionType.INVISIBILITY),
                factory.createPotion(PotionType.STRENGTH), factory.createPotion(PotionType.HEALING),
                factory.createPotion(PotionType.INVISIBILITY), factory.createPotion(PotionType.STRENGTH),
                factory.createPotion(PotionType.HEALING), factory.createPotion(PotionType.HEALING));

        bottomShelf = Arrays.asList(factory.createPotion(PotionType.POISON), factory.createPotion(PotionType.POISON),
            factory.createPotion(PotionType.POISON), factory.createPotion(PotionType.HOLY_WATER),
            factory.createPotion(PotionType.HOLY_WATER));
    }

    /**
     * 获取顶层架子上所有物品的只读列表
     *
     * @return 最顶层的药水
     */
    public final List<Potion> getTopShelf() {
        return new ArrayList<>(this.topShelf);
    }

    /**
     * 获取底层架子上所有物品的只读列表
     *
     * @return 最底层的药水架子
     */
    public final List<Potion> getBottomShelf() {
        return new ArrayList<>(this.bottomShelf);
    }

    /**
     * Drink all the potions.
     */
    public void drinkPotions() {
        log.info("喝顶层的药水");
        topShelf.forEach(Potion::drink);
        log.info("喝底架的药水");
        bottomShelf.forEach(Potion::drink);
    }
}
